package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "fallbackMethod")
public class HystrixConsumerOrderController {

    @Resource
    private PaymentService paymentService;

    @GetMapping("/consumer/hystrix/{id}")
    public String getOk(@PathVariable Integer id){
        return paymentService.getOk(id);
    };

    @GetMapping("/consumer/hystrixerror/{id}")
//    @HystrixCommand
    public String hystrixerror(@PathVariable Integer id){
        return paymentService.hystrixerror(id);
    };

    @GetMapping()
    public String hystrixerrorOrder(@PathVariable(value = "id") Integer id){
        return "消费端摆烂，我直接1.5秒就不执行了！";
    };


    public String fallbackMethod(){
        return "全局摆烂，不要给我面子！";
    }
}
